﻿<?php

/**
 * @author AnhSaoDem
 * @copyright 2011
 */

require('../config.php');
require('UTAPI.php');
require('../KiemTraDieuKien.php');


///////////////////////
echo "<b>TEST 1 FUNCTION laSo </b><Br>";
echo "kiem tra 1 chuoi nhap vao co phai la so hay khong<Br><Br>";

echo "Bo TEST 1: GT = 5 <br>";

assertTrue(laSo('5'));

echo "bo TEST 2: GT = 5.1 <br> ";
assertTrue(laSo('5.1'));

echo "bo TEST 3: GT = 5.1.1";
assertFalse(laSo('5.1.1'));

echo "Bo TEST 4: GT = abc <br>";

assertFalse(laSo('abc'));

echo "Bo TEST 5: GT = 1a3bc <br>";

assertFalse(laSo('1a3bc'));


/////////////////////////////////
// TEST CSDL SAN BAY

echo "<br> <b>TEST CSDL SAN BAY </b><br>";
echo "lay tat ca san bay tu CSDL sanbay<br><br>";

// Chen them san bay UNIT_T
$query = "INSERT INTO sanbay VALUES ('UNIT_T', 'TEST UNIT')";
@mysql_query($query);


// CHAY HAM
CSDL_SanBay($SB, $SB_T);

echo "IMPORT 1 SAN BAY VA KIEM TRA <br><br>";

// kiem tra co ton tai hay khong.
$check_exist = false ;

for($i = 1 ; $i <= $SB[0]; $i++)
{
    if ($SB[$i] == 'UNIT_T')
    {
        echo "Kiem tra sau khi import thi co dung hay khong<br>";
        assertEquals('TEST UNIT', $SB_T[$SB[$i]]);
        $check_exist = true;
    }
}

echo "Co ton tai gia tri vua import hay khong:<br>";
assertTrue($check_exist);


//Xoa 1 SAN BAY RA VA KIEM TRA LAI;

echo "XOA 1 SAN BAY RA VA KIEM TRA LAI <BR><BR>";

$query = "DELETE FROM sanbay WHERE MASB = 'UNIT_T'";
@mysql_query($query);

CSDL_SanBay($SB, $SB_T);


// kiem tra co ton tai hay khong.
$check_exist = false ;

for($i = 1 ; $i <= $SB[0]; $i++)
{
    if ($SB[$i] == 'UNIT_T')
    {
        $check_exist = true;
    }
}

echo "Kiem tra san bay co ton tai hay khong :<br>";
assertFalse($check_exist);



?>

<br /><br /><br /><br />
<p>TỔNG CỘNG : <?echo $test_true + $test_false?> BỘ</p>
<p>CHẠY ĐÚNG : <?echo $test_true?> </p>
<p>CHẠY SAI : <?echo $test_false?> </p>